package com.firexxx.vp.domain.vp.single.mlvdata;

import java.util.Base64;

/**
 * @description: TODO
 * @author: zhuangzhang2
 * @date: 2020-12-30 11:24
 */
public class MlvParseModelInfo {
    public MlvParseModelInfo() {
    }

    public static MlvModelData parseModelInfo(String ivector, boolean isNeedFloat) throws Exception {
        if (!ivector.isEmpty() && ivector.length() != 0) {
            byte[] bs = Base64.getDecoder().decode(ivector.trim());
            if (bs.length >= 824 && bs.length <= 6936) {
                MlvModelData m = isNeedFloat ? new MlvModelData(bs) : new MlvModelData(bs, false);
                return m;
            } else {
                throw new IllegalArgumentException("invalid-ivector, please check it");
            }
        } else {
            throw new IllegalArgumentException("input-ivector is null, please check it");
        }
    }

    public static MlvModelData parseModelInfo(byte[] bs, boolean isNeedFloat) throws Exception {
        if (bs.length >= 824 && bs.length <= 6936) {
            MlvModelData m = isNeedFloat ? new MlvModelData(bs) : new MlvModelData(bs, false);
            return m;
        } else {
            throw new IllegalArgumentException("invalid-ivector, please check it");
        }
    }

    public static MlvModelData parseHeadInfo(String ivecHead) throws Exception {
        if (!ivecHead.isEmpty() && ivecHead.length() != 0) {
            byte[] bs = Base64.getDecoder().decode(ivecHead.trim());
            if (bs.length < 88) {
                throw new IllegalArgumentException("input-ivector-head shorter than 88, please check it");
            } else {
                return new MlvModelData(bs, false);
            }
        } else {
            throw new IllegalArgumentException("input-ivector-head is null, please check it");
        }
    }

    public static MlvModelData parseHeadInfo(byte[] ivecHead) throws Exception {
        if (ivecHead.length < 88) {
            throw new IllegalArgumentException("input-ivector-head shorter than 88, please check it");
        } else {
            return new MlvModelData(ivecHead, false);
        }
    }
}
